package com.bluebench.bigul.service.resolver;

import java.util.Map;
import java.util.Set;

import com.bluebench.bigul.domain.Element;
import com.bluebench.bigul.exception.GraphicInitializationException;

/**
 * The GlobalElementResolver is responsible for resolving the global elements defined within the <global></global> tags in 
 * the template xml.
 * @author raghave.shukla
 *
 */
public class GlobalElementResolver extends DefaultExpressionResolver{
	
	public GlobalElementResolver() throws GraphicInitializationException {
		if(!IS_INITIALIZED){
			IS_INITIALIZED = true;
			super.resolve();			
		}
	}
	
	
	@Override
	public void resolve() throws GraphicInitializationException {
		Map<String,Element> elements = getGlobalElements();
		Set<String> keys = elements.keySet();
		for(String key : keys){
			
			ElementResolver eResolver = (ElementResolver)getInstance(ELEMENT_RESOLVER);
			eResolver.set(elements.get(key));
			eResolver.resolve();
		}
		
		for(String key : keys){			
			PrimitiveExpressionResolver primResolver = (PrimitiveExpressionResolver)getInstance(PRIMITIVE_RESOLVER);
			primResolver.set(elements.get(key));
			primResolver.resolve();
		}		
		
	}
	
}
